from enum import Enum
from typing import Optional
from pydantic import BaseModel, Field, validator

class RelationType(Enum):
    """标准关系类型枚举"""
    HAS_HAZARD = "hasHazard"
    HAS_COMPONENT = "hasComponent"
    DEPICTED_BY = "depictedBy"  # 修正拼写错误
    HAS_MOLECULAR_WEIGHT = "molWeight"

class EvidenceTriple(BaseModel):
    """多模态证据三元组"""
    head: str = Field(..., description="头实体ID")
    relation: str = Field(..., description="关系类型")
    tail: str = Field(..., description="尾实体ID或值")
    modality: str = Field(..., pattern="^(text|image|video)$")  # 修改这里
    source: str = Field(..., description="数据来源")
    confidence: float = Field(0.9, ge=0, le=1)
    timestamp: Optional[str] = Field(None, description="时间戳")

    @validator('relation')
    def validate_relation(cls, v):
        if v not in [t.value for t in RelationType]:
            raise ValueError(f"无效关系类型: {v}")
        return v